﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicJournal.Account.EditorAccount
{
    public partial class Patterns : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LinkButton_Click(object sender, EventArgs e)
        {
            UploadPanel.Visible = !UploadPanel.Visible;
        }

        protected void Button_Click(object sender, EventArgs e)
        {
            SqlDataSource1.InsertParameters[0].DefaultValue = TitleTextBox.Text;
            SqlDataSource1.InsertParameters[1].DefaultValue = DescriptionTextBox.Text;
            string FileName = Server.MapPath("..") + "\\files\\publications\\" + System.IO.Path.GetFileName(FileUpload1.FileName);
            SqlDataSource1.InsertParameters[2].DefaultValue = FileName;
            if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
            {
                FileUpload1.PostedFile.SaveAs(FileName);
            }
            SqlDataSource1.Insert();
            TitleTextBox.Text = null;
            DescriptionTextBox.Text = null;
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            WebClient client = new WebClient();
            Byte[] buffer = client.DownloadData(PatternGridView.SelectedDataKey.Value.ToString());
            if (buffer != null)
            {
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-length", buffer.Length.ToString());
                Response.BinaryWrite(buffer);
            }
        }

        protected void DeletePatternButton_Click(object sender, EventArgs e)
        {

        }
    }
}